<?php
namespace app\admin\controller;

use think\Controller;
use think\Session;
use app\admin\model\login;

class Index extends Controller
{
    public function index()
    {
        if(request()->isPost()){
            $captcha=input('verifycode');
            if(!captcha_check($captcha)){
                echo "<script>alert('验证失败！');</script>";
            }else{
//验证管理员账号密码
                $a=input('adminname');
                $p=input('password');
                $log=new Login;
                //返回值
                $result=$log->login($a,$p);

                if ($result==1) {
                    echo "<script>alert('密码错误！');</script>";
                }
                else if ($result==2) {
                    echo "<script>alert('账号不存在！');</script>";
                }
                else if ($result==3) {
                    $this->redirect('lipstick/index');
                }



            }
        }

        return $this->fetch();
    }
    public function show_captcha(){

        $captcha = new \think\captcha\Captcha();
        //$captcha->useZh=true;
        $captcha->zhSet="床前明月光疑是地上霜举头望思故乡";
        $captcha->fontSize = 20;
        $captcha->length   = 3;
        $captcha->useNoise = false;
        return $captcha->entry();

    }

    public function logout(){
        Session::clear();
        $this->redirect("index/index");
    }
}
